package jmine.tec.web.front.pack;

import jmine.tec.database.pack.populator.AbstractPopulatorDataSource;
import jmine.tec.database.pack.populator.PopulatorBean;
import jmine.tec.utils.collection.Mapper;
import jmine.tec.utils.collection.MapperUtils;
import jmine.tec.web.front.domain.BackOfficeRequestType;
import bancosys.tec.persist.dao.BaseDAO;

/**
 * Pack populator for request type
 * 
 * @author vinicius
 */
public class BackOfficeRequestTypeDataSource extends AbstractPopulatorDataSource<BackOfficeRequestType> {

    private BaseDAO<BackOfficeRequestType> backOfficeRequestTypeDAO;

    /**
     * {@inheritDoc}
     */
    public Iterable<PopulatorBean<BackOfficeRequestType>> load() {
        return MapperUtils.mapList(this.backOfficeRequestTypeDAO.findAllOrderedByPk(),
                new Mapper<BackOfficeRequestType, PopulatorBean<BackOfficeRequestType>>() {
                    public PopulatorBean<BackOfficeRequestType> apply(BackOfficeRequestType input) {
                        return new PopulatorBean<BackOfficeRequestType>(input, "front", "type", input.getMnemonic().toLowerCase() + ".xml");
                    }
                });
    }

    /**
     * @param backOfficeRequestTypeDAO the backOfficeRequestTypeDAO to set
     */
    public void setBackOfficeRequestTypeDAO(BaseDAO<BackOfficeRequestType> backOfficeRequestTypeDAO) {
        this.backOfficeRequestTypeDAO = backOfficeRequestTypeDAO;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public String toString() {
        return "PropertiesPopulatorDataSource";
    }

}
